#include "Instruction.hpp"
#include "3adCode.hpp"
#include "IdentTable.hpp"

#include <iostream>


Instruction::Instruction(CodeInstruction opCode) {
	this->opCode = opCode;
	this->operands[0] = NULL;
	this->operands[1] = NULL;
	this->operands[2] = NULL;
	this->identLabel = -1;
}

Instruction::Instruction(CodeInstruction opCode, Operand * operand1) {
	this->opCode = opCode;
	this->operands[0] = operand1;
	this->operands[1] = NULL;
	this->operands[2] = NULL;
	this->identLabel = -1;
}

Instruction::Instruction(CodeInstruction opCode, Operand * operand1, Operand * operand2) {
	this->opCode = opCode;
	this->operands[0] = operand1;
	this->operands[1] = operand2;
	this->operands[2] = NULL;
	this->identLabel = -1;
}

Instruction::Instruction(CodeInstruction opCode, Operand * operand1, Operand * operand2, Operand * operand3) {
	this->opCode = opCode;
	this->operands[0] = operand1;
	this->operands[1] = operand2;
	this->operands[2] = operand3;
	this->identLabel = -1;
	
}

Instruction::Instruction(CodeInstruction opCode, Operand operands[], int identLabel) {
}

Instruction::~Instruction() {
	for (int i=0 ; i<3 ; i++) {
		if (operands[i] != NULL) {
			delete operands[i];
		}
	}
}


void Instruction::show(IdentTable * identTable) {
	//show(identLabel); //se débrouille pour récupérer la table des ident et afficher son nom ou classe Ident qui le fait ?
	if (operands[0] != NULL)
		operands[0]->show(identTable);
	showCodeInstruction(opCode);
	if (operands[1] != NULL)
		operands[1]->show(identTable);
	if (operands[2] != NULL)
		operands[2]->show(identTable);
	std::cout << std::endl;
}
